<?php

namespace App\Http\Controllers;

use App\Jobs\SendReminderEmail;
use App\User;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Mail;

class MailController extends Controller
{
    public function send()
    {
        $name = "郭佳老大";
        $imgPath = 'http://laravelacademy.org/wp-statics/images/carousel/LaravelAcademy.jpg';
        $flag = Mail::send('emails.test', ['name'=>$name,'imgPath'=>$imgPath], function ($message) {
            $to = '310255981@qq.com';
            $message->to($to)->subject('测试邮件');

            $attachment = storage_path('app/files/test.docx');
            //在邮件中上传附件
            $message->attach($attachment, ['as'=>"=?UTF-8?B?".base64_encode('测试文档')."?=.docx"]);
        });
        if ($flag) {
            echo '发送邮件成功，请查收！';
        } else {
            echo '发送邮件失败，请重试！';
        }
    }

    //发送提醒邮件
    public function sendReminderEmail(Request $request, $id)
    {
        $user = User::findOrFail($id);
        $job = (new SendReminderEmail($user))->delay(60);
        $this->dispatch($job);
    }
}
